package com.wgg.common.codec;

import java.util.EnumMap;

/**
 * {@code protoBuf}使用需要线下单独生产 XXproto.java的文件类;
 * 如果{@code netty}中使用{@code protoBuf},要注意{@code ProtobufDecoder}和{@code ProtobufEncoder},只具有序列化功能,不具备半包处理功能;
 * 要在{@code netty}中使用{@code protoBuf}支持半包处理功能,需要使用{@code ProtobufVarint32FrameDecoder}和${@code ProtobufVarint32LengthFieldPrepender}或者自定义协议,行拆解包.
 * {@code protoBuf}要编码的类有多个,可以考虑父类{@code GeneratedMessage}的使用			
 * @author WSH
 */
public enum SerializerFactory {
	
	INSTANCE;

	public static enum SerialType {
		JDK,Hessian,Marshall,
	}
	
	private final static EnumMap<SerialType, Serializer> serialFactory;
	
	static {
		serialFactory = new EnumMap<SerializerFactory.SerialType, Serializer>(SerialType.class);
		serialFactory.put(SerialType.JDK, JdkSerializer.INSTANCE);
		serialFactory.put(SerialType.Hessian, HessianSerializer.INSTANCE);
		serialFactory.put(SerialType.Marshall, MarshallingSerializer.INSTANCE);
	}
	
	public Serializer getSerializer(SerialType serialType) {
		if (null == serialType) {
			throw new IllegalArgumentException("SerialType cann't be null...");
		}
		return serialFactory.get(serialType);
	}
}
